package com.kuzan.autocloud.common.model;

import com.kuzan.autocloud.common.util.UuidUtil;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>Description: </p>
 *
 * @author kuzank
 */
@Data
@MappedSuperclass
public abstract class Base {
    /**
     * 标题
     */
    @Column
    private String title;
    /**
     * 创建时间
     */
    @Column(length = 30)
    private String createtime = LocalDateTime.now().toString();
    /**
     * 创建人
     */
    @Column(length = 32)
    private String creator;
    /**
     * 更新时间
     */
    @Column(length = 30)
    private String updatetime = LocalDateTime.now().toString();
    /**
     * 描述、说明
     */
    @Lob
    @Column(columnDefinition = "TEXT")
    protected String description;
    /**
     * uuid
     */
    @Id
    @Column(length = 32)
    private String id = UuidUtil.randomUUID();
    /**
     * 是否禁用(业务上的禁用)
     */
    @Column(length = 3)
    private String disabled;
    /**
     * 排序
     */
    @Column(length = 30)
    private String sort;

    /**
     * @return 生成 c0000 规律的序号
     */
    private static Format ranksFormat = new DecimalFormat("0000");
    private static AtomicInteger count = new AtomicInteger(0);
    protected static String getSortIncrement() {
        count.incrementAndGet();
        return "c" + ranksFormat.format(count.get());
    }
}
